home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / TUT09NEW.ZIP / TUT9.TXT < prev   
Text File  |  1995-01-21  |  13KB  |  298 lines

  1.                    ╒═══════════════════════════════╕
  2.                    │         W E L C O M E         │
  3.                    │  To the VGA Trainer Program   │ │
  4.                    │              By               │ │
  5.                    │      DENTHOR of ASPHYXIA      │ │ │
  6.                    │      (updated by Snowman)     │ │ │
  7.                    ╘═══════════════════════════════╛ │ │
  8.                      ────────────────────────────────┘ │
  9.                        ────────────────────────────────┘
  10.  
  11.                            --==[ PART 9 ]==--
  12.  
  13.  
  14. [Note: things in brackets have been added by Snowman.  The original text
  15. has remained mostly unaltered except for the inclusion of C++ material]
  16.  
  17. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  18. ■ Introduction
  19.  
  20. Hi there! ASPHYXIA is BACK with our first MegaDemo, Psycho Neurosis! A
  21. paltry 1.3MB download is all it takes to see the group from Durbs first
  22. major production! We are quite proud of it, and think you should see it
  23. ;)
  24.  
  25. Secondly, I released a small little trainer (a trainerette ;-)) on
  26. RsaPROG and Connexctix BBS mail, also on the ASPHYXIA BBS as COPPERS.ZIP
  27. It is a small Pascal program demonstrating how to display copper bars in
  28. text mode. Also includes a check for horizontal retrace (A lot of people
  29. wanted it, that is why I wrote the program) (ASPHYXIA ... first with the
  30. trainer goodies ;-)  aargh, sorry, had to be done ))
  31.  
  32. Thirdly, sorry about the problems with Tut 8! If you had all the
  33. checking on, the tutorial would probably die on the first points. The
  34. reason is this : in the first loop, we have DrawPoints then
  35. RotatePoints. The variables used in DrawPoints are set in RotatePoints,
  36. so if you put RotatePoints before DrawPoints, the program should work
  37. fine. Alternatively, turn off error checking 8-)
  38.  
  39. Fourthly, I have had a surprisingly large number of people saying that
  40. "I get this, like, strange '286 instructions not enabled' message!
  41. What's wrong with your code, dude?"  To all of you, get into Pascal, hit
  42. Alt-O (for options), hit enter and a 2 (for Enable 286 instructions). Hard
  43. hey? Doesn't anyone EVER set up their version of Pascal?
  44.  
  45. Now, on to todays tutorial! 3D solids. That is what the people wanted,
  46. that is what the people get! This tutorial is mainly on how to draw the
  47. polygon on screen. For details on how the 3D stuff works, check out tut
  48. 8.
  49.  
  50.  
  51.  
  52. If you would like to contact me, or the team, there are many ways you
  53. can do it : 1) Write a message to Grant Smith/Denthor/Asphyxia in private mail
  54.                   on the ASPHYXIA BBS.
  55.             2) Write to Denthor, EzE or Goth on Connectix.
  56.             3) Write to :  Grant Smith
  57.                            P.O.Box 270 Kloof
  58.                            3640
  59.                            Natal
  60.             4) Call me (Grant Smith) at (031) 73 2129 (leave a message if you
  61.                   call during varsity)
  62.             5) Write to mcphail@beastie.cs.und.ac.za on InterNet, and
  63.                   mention the word Denthor near the top of the letter.
  64.  
  65. NB : If you are a representative of a company or BBS, and want ASPHYXIA
  66.        to do you a demo, leave mail to me; we can discuss it.
  67. NNB : If you have done/attempted a demo, SEND IT TO ME! We are feeling
  68.         quite lonely and want to meet/help out/exchange code with other demo
  69.         groups. What do you have to lose? Leave a message here and we can work
  70.         out how to transfer it. We really want to hear from you!
  71.  
  72.  
  73.  
  74. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  75. ■ How to draw a polygon
  76.  
  77. Sounds easy enough, right? WRONG! There are many, many different ways to
  78. go about this, and today I'll only be showing you one. Please don't take
  79. what is written here as anything approaching the best method, it is just
  80. here to get you on your way...
  81.  
  82. The procedure I will be using here is based on something most of us
  83. learned in standard eight ... I think. I seem to recall doing something
  84. like this in Mrs. Reids maths class all those years ago ;)
  85.  
  86. Take two points, x1,y1 and x2,y2. Draw them :
  87.  
  88.                   + (x1,y1)
  89.                    \
  90.                      \  <-- Point a somewhere along the line
  91.                        \
  92.                          + (x2,y2)
  93.  
  94. Right, so what we have to do is this : if we know the y-coord of a, what
  95. is it's x-coord? To prove the method we will give the points random
  96. values.
  97.  
  98.                  + (2,10)
  99.                   \
  100.                     \  <-- a.y = 12
  101.                       \
  102.                         +  (15,30)
  103.  
  104. Right. Simple enough problem. This is how we do it :
  105.    (a.y-y1) = (12 - 10)  {to get a.y as though y1 was zero}
  106.    *(x2-x1) = *(15 - 2)  {the total x-length of the line}
  107.    /(y2-y1) = /(30 - 10) {the total y-length of the line}
  108.         +x1 = +2         { to get the equation back to real coords}
  109.  
  110. So our equation is :  (a.y-y1)*(x2-x1)/(y2-y1)+x4    or
  111.                       (12-10)*(15-2)/(30-10)+2
  112.       which gives you :
  113.                       2*13/20+2 = 26/20+2
  114.                                 = 3.3
  115.  
  116. That means that along the line with y=12, x is equal to 3.3. Since we
  117. are not concerned with the decimal place, we replace the  /  with a div,
  118. which in Pascal gives us an integer result, and is faster too. All well
  119. and good, I hear you cry, but what does this have to do with life and
  120. how it relates to polygons in general. The answer is simple. For each of
  121. the four sides of the polygon we do the above test for each y line. We
  122. store the smallest and the largest x values into separate variables for
  123. each line, and draw a horizontal line between them. Ta-Dah! We have a
  124. cool polygon!
  125.  
  126. For example : Two lines going down :
  127.     
  128.                 +             +
  129.                / <-x1     x2->|   <--For this y line
  130.              /                |
  131.            +                  +
  132.  
  133. Find x1 and x2 for that y, then draw a line between them. Repeat for all
  134. y values.
  135.  
  136. Of course, it's not as simple as that. We have to make sure we only
  137. check those y lines that contain the polygon (a simple min y, max y test
  138. for all the points). We also have to check that the line we are
  139. calculating actually extends as far as where our current y is (check
  140. that the point is between both y's). We have to compare each x to see
  141. weather it is smaller then the minimum x value so far, or bigger then
  142. the maximum (the original x min is set as a high number, and the x max
  143. is set as a small number). We must also check that we only draw to the
  144. place that we can see ( 0-319 on the x ; 0-199 on the y (the size of the
  145. MCGA screen))
  146.  
  147. To see how this looks in practice, have a look at the sample code
  148. provided. (Mrs. Reid would probably kill me for the above explanation,
  149. so when you learn it in school, split it up into thousands of smaller
  150. equations to get the same answer ;))
  151.  
  152. Okay, that's it! What's that? How do you draw a vertical line? Thats
  153. simple ...
  154.  
  155. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  156. ■ Drawing a vertical line
  157.  
  158. Right, this is a lot easier than drawing a normal line (Tut 5 .. I
  159. think), because you stay on the same y value. So, what you do is you set
  160. ES to the screen you want to write to, and get DI to the start of the
  161. y-line (see earlier trainers for a description of how SEGMENT:OFFSET
  162. works.
  163.  
  164. IN   : x1 , x2, y, color, where
  165.  
  166.            asm
  167.              mov    ax,where
  168.              mov    es,ax
  169.              mov    di,y
  170.              mov    ax,y
  171.              shl    di,8   { di:=di*256 }
  172.              shl    ax,6   { ax:=ax*64 }
  173.              add    di,ax  { di := (y*256)+(y*64) := y*320 Faster then a
  174.                              straight multiplication }
  175.  
  176. Right, now you add the first x value to get your startoff.
  177.              add    di,x1
  178. Move the color to store into ah and al
  179.              mov    al,color
  180.              mov    ah,al       { ah:=al:=color }
  181. then get CX equal to how many pixels across you want to go
  182.              mov    cx,x2
  183.              sub    cx,x1   { cx:=x2-x1 }
  184. Okay, as we all know, moving a word is a lot faster then moving a byte,
  185. so we halve CX
  186.              shr    cx,1    { cx:=cx/2 }
  187. but what happens if CX was an odd number. After a shift, the value of
  188. the last number is placed in the carry flag, so what we do is jump over
  189. a single byte move if the carry flag is zero, or execute it if it is
  190. one.
  191.             jnc     @Start  { If there is no carry, jump to label Start }
  192.             stosb           { ES:[DI]:=al ; increment DI }
  193.         @Start :            { Label Start }
  194.             rep     stosw   { ES:[DI]:=ax ; DI:=DI+2; repeat CX times }
  195.  
  196. Right, the finished product looks like this :
  197.  
  198. [Pascal]
  199.  
  200.   Procedure Hline (x1,x2,y:word;col:byte;where:word); assembler;
  201.     { This draws a horizontal line from x1 to x2 on line y in color col }
  202.   asm
  203.     mov   ax,where
  204.     mov   es,ax
  205.     mov   ax,y
  206.     mov   di,ax
  207.     shl   ax,8
  208.     shl   di,6
  209.     add   di,ax
  210.     add   di,x1
  211.  
  212.     mov   al,col
  213.     mov   ah,al
  214.     mov   cx,x2
  215.     sub   cx,x1
  216.     shr   cx,1
  217.     jnc   @start
  218.     stosb
  219.   @Start :
  220.     rep   stosw
  221.   end;
  222.  
  223. [C++]
  224.  
  225.   void Hline (word X1, word X2, word Y, byte Col, word Where) {
  226.     asm {
  227.       mov     ax, [Where]  // move segment of Where to AX
  228.       mov     es, ax       // set ES to segment of Where
  229.       mov     ax, [Y]      // set AX to Y
  230.       mov     di, ax       // set DI to Y
  231.       shl     ax, 8        // shift AX left 8 places (multiply Y by 256)
  232.       shl     di, 6        // shift DI left 6 places (multiply Y by 64)
  233.       add     di, ax       // add AX to DI (Y*64 + Y*256 = Y*320)
  234.       add     di, [X1]     // add the X1 offset to DI
  235.       mov     al, [Col]    // move Col to AL
  236.       mov     ah, al       // move Col to AH (we want 2 copies for word moving)
  237.       mov     cx, [X2]     // move X2 to CX
  238.       sub     cx, [X1]     // move the change in X to CX
  239.       shr     cx, 1        // divide change in X by 2 (for word moving)
  240.       jnc     Start        // if we have an even number of moves, go to Start
  241.       stosb                // otherwise, move one byte more
  242.     }
  243.     Start: asm {
  244.       rep     stosw        // do it!
  245.     }
  246.   }
  247.  
  248. Done!
  249.  
  250. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  251. ■  In closing
  252.  
  253. This 3D system is still not perfect. It needs to be faster, and now I
  254. have also dumped the problem of face-sorting on you! Nyahahahaha!
  255.  
  256.            [ My sister and I were driving along the other day when she
  257.                asked me, what would I like for my computer.
  258.              I thought long and hard about it, and came up with the
  259.                following hypothesis. When a girl gets a Barbie doll, she
  260.                then wants the extra ballgown for the doll, then the
  261.                hairbrush, and the car, and the house, and the friends
  262.                etc.
  263.              When a guy gets a computer, he wants the extra memory, the
  264.                bigger hard drive, the maths co-pro, the better
  265.                motherboard, the latest software, and the bigger monitor
  266.                etc.
  267.              I told my sister all of this, and finished up with : "So as
  268.                you can see, computers are Barbie dolls for MEN!"
  269.              She called me a chauvinist. And hit me. Hard.
  270.                                                                    ]
  271.                                                        - Grant Smith
  272.                                                            19:24
  273.                                                              26/2/94
  274.  
  275. See you next time!
  276.   - Denthor
  277.  
  278. These fine BBS's carry the ASPHYXIA DEMO TRAINER SERIES : (alphabetical)
  279.  
  280. ╔══════════════════════════╦════════════════╦═════╦═══╦════╦════╗
  281. ║BBS Name                  ║Telephone No.   ║Open ║Msg║File║Past║
  282. ╠══════════════════════════╬════════════════╬═════╬═══╬════╬════╣
  283. ║ASPHYXIA BBS #1           ║(031) 765-5312  ║ALL  ║ * ║ *  ║ *  ║
  284. ║ASPHYXIA BBS #2           ║(031) 765-6293  ║ALL  ║ * ║ *  ║ *  ║
  285. ║Connectix BBS             ║(031) 266-9992  ║ALL  ║   ║ *  ║ *  ║
  286. ╚══════════════════════════╩════════════════╩═════╩═══╩════╩════╝
  287.  
  288. Open = Open at all times or only A/H
  289. Msg  = Available in message base
  290. File = Available in file base
  291. Past = Previous Parts available
  292.  
  293. Does no other BBS's ANYWHERE carry the trainer? Am I writing this for
  294. three people who get it from one of these BBS's each week? Should I go
  295. on? (Hehehehe ... I was pleased to note that Tut 8 was THE most
  296. downloaded file from ASPHYXIA BBS last month ... )       
  297.  
  298.